import ctypes

# 加载对应位数动态链接库
_CvCameraIndex = ctypes.cdll.LoadLibrary(r'J:\cv-camera-index\build\Release\CvCameraIndex.dll')
_CvCameraIndex.getCameraIndex.argtypes = [ctypes.c_char_p]
_CvCameraIndex.getCameraIndex.restype = ctypes.c_int


def get_camera_id(hwid: str) -> int:
    """
    获取cv.VideoCapture(camera_index, cv2.CAP_DSHOW)参数camera_index

    Parameters:
    - hwid : str, 硬件标识, 不区分大小写, 如 vid_1234&pid_4321, 或 op000001

    Returns:
    - int, camera_index
        """
    return _CvCameraIndex.getCameraIndex(bytes(hwid, encoding='utf-8'))

if __name__ == '__main__':
    camera_index = get_camera_id('pid_b111')
    print(camera_index)
